# This file replicates the results from "The Populist Appeal: Personality and Anti-establishment Communication" by Bakker, Schumacher & Rooduijn

rm(list=ls())
source("Functions.R")

#Study 1-------------------------
#Study 1: UK Understanding Society Data
source("Study 1/Manipulate Data/Study1_UK_UnderstandingSociety_coding.R")
source("Study 1/Run Results/Study1_UK_UnderstandingSociety_results.R")
 ## ignore warnings about LAVAAN

#Study 1: UK British Election Study
source("Study 1/Manipulate Data/Study1_UK_BritishElectionStudies_coding.R")
source("Study 1/Run Results/Study1_UK_BritishElectionStudies_results.R")

#Study 1: Germany 
source("Study 1/Manipulate Data/Study1_Germany_coding.R")
source("Study 1/Run Results/Study1_Germany_results.R")
 ## ignore warnings about GLM

#Study 1: Denmark 
source("Study 1/Manipulate Data/Study1_Denmark_coding.R")
source("Study 1/Run Results/Study1_Denmark_results.R")
  ## ignore warnings about alpha (occurs when calculating alpha for 2 items) and lavaan

#Study 1: Netherlands: Dutch Election Study 2012
source("Study 1/Manipulate Data/Study1_NL12_coding.R")
source("Study 1/Run Results/Study1_NL12_results.R")

#Study 1: Netherlands: Dutch EU Eelction Study 2014
source("Study 1/Manipulate Data/Study1_NL14_coding.R")
source("Study 1/Run Results/Study1_NL14_results.R")

#Study 1: Netherlands: Dutch Election Study 2017
source("Study 1/Manipulate Data/Study1_NL17_coding.R")
source("Study 1/Run Results/Study1_NL17_results.R")

#Study 1: Switzerland: Swiss Household Panel 2009
source("Study 1/Manipulate Data/Study1_Swiss_Household09_coding.R")
source("Study 1/Run Results/Study1_Swiss_Household09_results.R")
  # ignore warnings about alpha (see line 24)

#Study 1: Switzerland: Swiss Household Panel 2015
source("Study 1/Manipulate Data/Study1_Swiss_Household15_coding.R")
# ignore warnings about read.dta
source("Study 1/Run Results/Study1_Swiss_Household15_results.R")
# ignore warnings about lavaan

#Study 1: Switzerland: Swiss Election Studies 2015
source("Study 1/Manipulate Data/Study1_Swiss_Election15_coding.R")
source("Study 1/Run Results/Study1_Swiss_Election15_results.R")

#Study 1: Spain
source("Study 1/Manipulate Data/Study1_Spain_coding.R")
source("Study 1/Run Results/Study1_Spain_results.R")
  # ignore warnings about alpha

#Study 1: Venezuela
source("Study 1/Manipulate Data/Study1_Venezuela_coding.R") 
source("Study 1/Run Results/Study1_Venezuela_results.R")
  # issues with alphas

#Study 1: U.S. ANES
source("Study 1/Manipulate Data/Study1_US_ANES_coding.R")
source("Study 1/Run Results/Study1_US_ANES_results.R")

#Study 1: Meta-analysis 
source("Study 1/Run Results/Study1_meta.R")

#Study 1: Make Figure 1
source("Study 1/Run Results/Study1_Figure1.R") 
  # ignore warnings. Same as warning on line 19

#Study 1: Appendix A.15
source("Study 2/Study2_coding.R") # ignore warnings about NA coding
source("Study 1/Run Results/Study1_SSI_Appendix_A.15.R")
  # ignore warnings about NA by default creation

#Study 1: Appendix A.16
source("Study 1/Run Results/Study1_SSI_Appendix_A16.R")

#Study 1: Not controlling for cynicism
source("Study 1/Run Results/Study1_Figure1_no_cynicism.R") 

#Study 1: Not controlling for left-right ideology
source("Study 1/Run Results/Study1_Figure1_lrideology.R")
  # ignore warnings, same as warning on line 19

#Study 1: Appendix A18
source("Study 1/Run Results/Study1_Appendix_A18.R")
# ignore warnings

#Study 1: Appendix A19
source("Study 1/Run Results/Study1_Appendix_A19.R")

#Study 2: ---------------------------------------------------------------
source("Study 2/Study2_Analyses.R")
 #   Ignore warning about NAs introduced by coercion

#Study 2: LISS panel
source("Study 2/Study2_Appendix_B10.R")
  # ignore warnings about read.dta and stata labels

# Write to Overleaf dir
outdir <- paste0("C:/",unlist(str_split(getwd(),"[/]"))[2],"/",unlist(str_split(getwd(),"[/]"))[3],"/","Dropbox/Apps/Overleaf/personality-populism-populist/")
file.copy(from="/Figures", to=paste0(outdir,"Figures"))
file.copy(from="/Tables", to=paste0(outdir,"Tables"))
